package cms.bean.topic;

import cms.utils.Verification;
import com.google.common.collect.EnumMultiset;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.collections4.EnumerationUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.EnumUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;

/**
 * 隐藏标签类型
 *
 */
@AllArgsConstructor
@Getter
public enum HideTagType {
	//输入密码可见
	PASSWORD(10,(inputValue)->inputValue.length() <=50),
	//评论话题可见
	COMMENT(20,(inputValue)->true),
	//达到等级可见
	GRADE(30,(inputValue)-> Verification.isPositiveInteger(inputValue)),
	//积分购买可见
	POINT(40,(inputValue)->Verification.isPositiveInteger(inputValue)),
	//余额购买可见
	AMOUNT(50,(inputValue)->Verification.isAmount(inputValue) && new BigDecimal(inputValue.trim()).compareTo(new BigDecimal("0")) > 0);
	Integer name;
	Predicate<String> validate;
	/**
	 * Name与枚举的对应关系
	 */
	private static Map<Integer,HideTagType> hideTagTypeMap =new HashMap<>();

	/**
	 * 是否包含
	 * @param name
	 * @return
	 */
	public static boolean contains(Integer name){
		return buildByName(name)!=null;
	}

	/**
	 * 根据值转化成对应类型的隐藏类型
	 * @param name
	 * @return
	 */
	public static HideTagType buildByName(Integer name) {
		if(name!=null) {
			if(MapUtils.isEmpty(hideTagTypeMap)){
				for (HideTagType tagType : HideTagType.values()) {
					hideTagTypeMap.put(tagType.name, tagType);
				}
			}
			return hideTagTypeMap.get(name);
		}
		return null;
	}
}
